package cn.xaut.剑指offer.m20;

import cn.xaut.剑指offer.m01.ListNode;

// 剑指 Offer 22. 链表中倒数第k个节点 
public class demo22 {

    public ListNode getKthFromEnd(ListNode head, int k) {

        ListNode fast = head, slow = head;
        for (int i = 0; i < k; i++) 
            fast = fast.next;
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
